<template>
    <el-dialog
        title="提示"
        :visible.sync="dialogStatus"
        width="400px"
        :close-on-click-modal="true"
        :before-close="closeDialog"
        top="30vh"
    >
        <div class="dialog-title" slot="title">重置密码</div>
        <div class="dialog-body">
            <el-form ref="form" :model="formData" label-width="80px">
                <el-form-item label="新密码" prop="password" :rules="[{required:true,message:'请输入新密码',trigger:'blur'}]" style="margin-bottom:10px;">
                    <el-input type="password" size="small" v-model="formData.password"></el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="repassword" :rules="[
                    {required:true,message:'请输入确认密码',trigger:'blur'}
                ]">
                    <el-input type="password" size="small" v-model="formData.repassword"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="onSubmit('form')">立即提交</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="dialog-footer" slot="footer"></div>
    </el-dialog>
</template>

<script>
export default {
    data(){
        return {
            dialogStatus:false,
            formData:{
                password:'',
                repassword:''
            },
            form:{
                mchNo:'',
                pass:'',
            }
        }
    },
    methods:{
        // 提交数据
        onSubmit(form){
            this.$refs[form].validate((valid) => {
                if (valid != false) {
                    if(this.formData.password != this.formData.repassword){
                        this.$message.error('两次密码不一致！');
                    }else{
                        this.form.pass = this.formData.password;
                        this.$http.post('/api/altmch/setPass', this.form).then(result => {
                            if(result.code == 200){
                                this.$message.success({
                                    message:result.msg,
                                    onClose:_ => {},
                                });
                                this.closeDialog();
                            }else{
                                this.$message.error(result.msg);
                            }
                        });
                    }
                }
            });
        },
        // 显示弹窗
        openDialog(e, index){
            this.form.mchNo = e.mchNo;
            this.dialogStatus = true;
        },
        // 关闭回调
        closeDialog(e){
            this.dialogStatus = false;
            this.$refs['form'].resetFields();
        },
    },
}
</script>

<style lang="less" scoped>
::v-deep(.el-form){
    .el-form-item{
        .el-form-item__content{
            margin-bottom:10px;
        }
    }
    .el-form-item.is-required{}
}
</style>
